/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MaterialPack;

import javax.microedition.lcdui.Image;
import Supporter.*;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
/**
 *
 * @author Van persie
 */
public class InfoPanel extends MaterialObject {
    
    public static final int ANC_MIDDLE = 1;
    public static final int ANC_LEFT = 0;
    
    private String text = null;
    Font myFont = null;
    private boolean isNoBackground = false;
    private boolean  isTransparentBackground = false;
    private boolean isAlphaBlend = false;
    private int AnchorMode ;
    
    Image buffer = null;
    
    int red,green,blue;
    public InfoPanel(String backgPath,String Info, int  x,int y, int wid,int hei,Font font  )
    {
        
        GetGraphicsInfo(x, y, wid, hei);
        text = Info;
        LoadImage(backgPath,false,wid,hei);
                
        myFont = font;
        isVisible = true;
        isNoBackground = false;
        AnchorMode =  ANC_MIDDLE;
        
        red = green = blue = 0;
        //PaintBuffer();
    }
    public void SetColorText(int r, int g, int b)
    {
        red = r;
        green = g;
        blue = b;
    }
    public void deActive()
    {
        
    }
    public void Active()
    {
    }
//    public final void PaintBuffer()
//    {
//       
//        buffer = Image.createImage(width, height);
//       
//        
//        Graphics g = buffer.getGraphics();
//        if(isNoBackground == false)
//        {
//            g.drawImage(background, 0, 0, Graphics.TOP | Graphics.LEFT);
//        }
//         g.setFont(myFont);
//        if(AnchorMode == ANC_LEFT)
//            g.drawString(getText(), 0, 0, Graphics.TOP | Graphics.LEFT);
//        else 
//            g.drawString(getText(), 0 + getWidth()/2 , 0 + getHeight()/6  , Graphics.HCENTER | Graphics.TOP);
//
//        if(isNoBackground)
//            buffer = ImageSupporter.transparent(buffer);
//        if(isAlphaBlend)
//            buffer = ImageSupporter.alphaBlend(buffer);
//        if(isTransparentBackground)
//            buffer = ImageSupporter.transparent(buffer);
//        
//        
//    }
//    public void SetAlphaBack()
//    {
//        isAlphaBlend = true;
//        PaintBuffer();
//    }
//    public void TransBackground(boolean decide )
//    {
//        isTransparentBackground = decide;
//        PaintBuffer();
//        
//    }
    public void paint(Graphics g)
    {
        if(IsVisible() == true)
        {
            //g.drawImage(buffer, xPos, yPos,Graphics.TOP | Graphics.LEFT);
            if(isNoBackground == false)
                g.drawImage(background, getxPos(), getyPos(),Graphics.TOP | Graphics.LEFT);
            g.setFont(myFont);
            int OldCor = g.getColor();
            g.setColor(red, green, blue);
            if(AnchorMode == ANC_LEFT)
                g.drawString(getText(), getxPos(), getyPos(), Graphics.TOP | Graphics.LEFT);
            else 
                g.drawString(getText(), getxPos() + getWidth()/2 , getyPos() + getHeight()/6  , Graphics.HCENTER | Graphics.TOP);

            g.setColor(OldCor);
        }        
    }

    /**
     * @return the isNoBackground
     */
    public boolean isNoBackground() {
        return isNoBackground;
    }

    /**
     * @param isNoBackground the isNoBackground to set
     */
    public void setNoBackground(boolean bit) {
        isNoBackground = bit;
        //PaintBuffer();
    }

    /**
     * @return the AnchorMode
     */
    public int getAnchorMode() {
        return AnchorMode;
    }

    /**
     * @param AnchorMode the AnchorMode to set
     */
    public void setAnchorMode(int AnchorMode) {
        this.AnchorMode = AnchorMode;
    }

    /**
     * @return the text
     */
    public String getText() {
        return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
        this.text = text;
    }
}
